home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / demo / demosrc / sets__define.pro < prev    next >
Text File  |  1997-07-08  |  6KB  |  162 lines

  1. ;-----------------------------------------------------------------------------
  2. ;  This is the Definition File for the SETS class.  This file includes the
  3. ;  following set methods:
  4. ;    Init   - Initialize a SETS object
  5. ;    CleanUp - Clean up a SETS object.
  6. ;   GetProperty - Obtain property information for a given SETS object.
  7. ;
  8.  
  9. ;*****************************************************************************
  10. ;  Sets::Init:           Initialize an instance of the 'sets' class.
  11. ;  Inputs:            name, [data, op, set1Name, set2Name, set1Size, set2Size]
  12. ;  Outputs:           1B - success or 0B - failure.
  13. ;  Side Effects:      On success an instance of the 'sets' class is created.
  14. ;
  15. ;*****************************************************************************
  16. function Sets::Init , name, data, $
  17.         OP = op, SET1_NAME =set1Name, SET2_NAME = set2Name, $
  18.         SET1_SIZE = set1Size, SET2_SIZE = set2Size
  19.  
  20.     FORWARD_FUNCTION TypeOf
  21.  
  22.     ; Check to see that the name argument is passed in.
  23.     ;
  24.     if N_PARAMS() lt 1 then begin
  25.           return, 0b
  26.     endif
  27.  
  28.     self.name = name
  29.  
  30.     ; If this new object is the result of a set operation then
  31.     ; define data for the operation, and the 'parent' objects.
  32.     ;
  33.     if N_ELEMENTS(op) gt 0 then begin
  34.         self.op = op
  35.           if N_ELEMENTS(set1Name) gt 0 then $
  36.               self.set1Name = set1Name
  37.           if N_ELEMENTS(set2Name) gt 0 then $
  38.               self.set2Name = set2Name
  39.         if N_ELEMENTS(set1Size) gt 0 then $
  40.               self.set1Size = set1Size
  41.           if N_ELEMENTS(set2Size) gt 0 then $
  42.               self.set2Size = set2Size
  43.  ;**** Error would occur if set1Name or set2Name are undefined!!!!!
  44.         opDesc = 'This is the ' + STRLOWCASE(op) + ' of set ' $
  45.                 + set1Name + ' and set ' + set2Name + '.  '
  46.     endif else $
  47.         opDesc = ''
  48.  
  49.     ;  If the object has data then initialize the appropriate instance data.
  50.     ;
  51.       if ((N_PARAMS() eq 2) and (N_ELEMENTS(data) gt 0))then begin
  52.         self.type = TypeOf(data)
  53.           uniqData = data[UNIQ(data, SORT(data))]
  54.         self.pData = PTR_NEW(uniqData)
  55.           self.size = N_ELEMENTS(uniqData)
  56.  
  57.         ; Create the object's description data
  58.         ;
  59.           elementDesc = 'This set contains ' + STRTRIM(STRING(self.size),2) + $
  60.               ' unique ' +self.type
  61.  
  62.           if self.size gt 1 then $
  63.               elementDesc = elementDesc + 's.  ' $
  64.           else $
  65.               elementDesc = elementDesc + '.  '
  66.  
  67.         minDesc = 'The minimum is ' + STRTRIM(STRING(MIN(uniqData)),2) + ' and '
  68.           maxDesc = 'the maximum is ' + STRTRIM(STRING(MAX(uniqData)),2) + '.'
  69.            mainDesc = 'Set ' + name + ':  ' + opDesc + elementDesc + minDesc + maxDesc
  70.  
  71.       endif else begin   ; Empty Set object
  72.         self.size = 0
  73.         mainDesc = 'Set '+ name + ':  ' + opDesc + 'The result is the Empty Set.'
  74.       endelse
  75.  
  76.     self.pDesc = PTR_NEW([mainDesc]) ; Create a pointer to the description data
  77.       return, 1b
  78. end
  79.  
  80.  
  81. ;*****************************************************************************
  82. ;  Sets::GetProperty: Pass instance data to the caller
  83. ;  Inputs:            NONE
  84. ;  Outputs:           [data, desc, name, op, size, set1Name, set2Name,
  85. ;                        set1Size, set2Size, type]
  86. ;  Side Effects:      NONE
  87. ;
  88. ;*****************************************************************************
  89. pro Sets::GetProperty, DATA = data, $
  90.          DESC = desc, NAME = name, OP = op, SIZE = size, $
  91.            SET1_NAME = set1Name, SET2_NAME = set2Name, $
  92.            SET1_SIZE = set1Size, SET2_SIZE = set2Size, TYPE = type
  93.  
  94.     ; Check to see which properties are requested and return them to
  95.     ; the caller
  96.     ;
  97.     if (ARG_PRESENT(size) or ARG_PRESENT(data)) then begin
  98.           size   = self.size
  99.           if size ne 0 then $      ; Contains data?
  100.                data  = *self.pData
  101.        endif
  102.        if ARG_PRESENT(desc) then $
  103.            desc   = *self.pDesc
  104.        if ARG_PRESENT(name) then $
  105.           name   = self.name
  106.       if ARG_PRESENT(op) then $
  107.           op = self.op
  108.       if ARG_PRESENT(set1Name) then $
  109.           set1Name = self.set1Name
  110.       if ARG_PRESENT(set2Name) then $
  111.           set2Name = self.set2Name
  112.       if ARG_PRESENT(set1Size) then $
  113.           set1Size = self.set1Size
  114.       if ARG_PRESENT(set2Size) then $
  115.           set2Size = self.set2Size
  116.       if ARG_PRESENT(type) then $
  117.           type   = self.type
  118. end
  119.  
  120.  
  121. ;*****************************************************************************
  122. ;  Sets::CleanUp: Free any pointers used by the object
  123. ;  Inputs:            NONE
  124. ;  Outputs:           NONE
  125. ;  Side Effects:      Frees self.pData and self.pDesc
  126. ;
  127. ;*****************************************************************************
  128. pro Sets::CleanUp
  129.  
  130.     ; Free data and description pointers if it is valid
  131.     ;
  132.       if PTR_VALID(self.pData) then $
  133.         PTR_FREE, self.pData
  134.       if PTR_VALID(self.pDesc) then $
  135.           PTR_FREE, self.pDesc
  136. end
  137.  
  138.  
  139. ;*****************************************************************************
  140. ;  Sets__Define: Define the class structure for the 'sets' class
  141. ;  Inputs:            NONE
  142. ;  Outputs:           NONE
  143. ;  Side Effects:      Creates definition of 'sets' structure in heap
  144. ;
  145. ;*****************************************************************************
  146. pro Sets__Define
  147.  
  148.     junk = { sets , $
  149.         pData:PTR_NEW()  ,      $  ; the contents of the set
  150.         pDesc: PTR_NEW()  ,     $  ; description of set
  151.         name: '' ,              $  ; one letter name
  152.         op: '',                 $  ; the set operation which produced this set
  153.         set1Name: '',             $  ; Name of 'parent' set 1
  154.         set2Name: '',             $  ; Name of 'parent' set 1
  155.         set1Size: 0L,             $  ; # of elements in 'parent' set 1
  156.         set2Size: 0L,             $  ; # of elements in 'parent' set 2
  157.         size: 0L ,              $  ; # of unique elements
  158.         type:''                $  ; datatype
  159.         }
  160.  
  161. end
  162.